package com.jin;

import com.jin.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class AnnotationConsumerMain {

    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);

        final ExecutorService executeThreadPool = Executors.newFixedThreadPool(10);

        while (true) {
            executeThreadPool.submit(() -> service.sayHello("world", 100));
            executeThreadPool.submit(() -> service.sayHello2("world", 100));
            executeThreadPool.submit(() -> service.sayHello3("world", 100));
            TimeUnit.MILLISECONDS.sleep(20);
        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "bean")
    @ComponentScan("com.jin.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
